package cn.zkld.web;

import cn.zkld.Data.FrontResult;
import cn.zkld.model.GoodsInfo;
import cn.zkld.service.SelectGoodsListByIDService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor;
import com.sun.istack.internal.NotNull;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通过商品种类id查询web层
 * Created by 李景辉 on 2017/12/6.
 *
 */
@Controller
public class SelectGoodsBySortIDController extends Base {
    @Resource
    private SelectGoodsListByIDService selectGoodsListByIDService;

    /**
     * 通过商品种类id查询商品
     * @param parent_id
     * @return
     */
    @RequestMapping(value="/selectGoodsBySort",method = RequestMethod.GET)
    @ResponseBody
    public FrontResult<List<GoodsInfo>> selectGoodsBySort(@RequestParam("parent_id") int parent_id){
        System.out.println(parent_id);
        /*将商品种类id放进session，在价格排序中使用*/
        request.getSession().setAttribute("parent_id",parent_id);
        try {
            List<GoodsInfo> list = selectGoodsListByIDService.selectGoodsBySort(parent_id);
            return FrontResult.wrapSuccessfulResult(list);
            /*map.put("status",0);
            map.put("message", "success");
            map.put("data", list);*/
        }catch (Exception e){
            return FrontResult.wrapFailureResult();
        }
    }
}
